# makefile

# This is the main makefile for this Interactive C project.

.DEFAULT : compileroutput

ProjectDir = $(shell pwd)


# Source
ICFiles = $(shell ls $(ProjectDir)/*.ic)
SimFile = $(ProjectDir)/boxcalc.ic


# Targets
OutputFiles = $(ICFiles:%.ic=%.out)
DiffFile = $(ProjectDir)/changes-$(shell date +%Y.%m.%d-%H.%M.%S).diff


# Tools
ICBinary = $(ProjectDir)/iccli
ICLibDir = $(ProjectDir)/lib/handyboard
ICCommand = $(ICBinary) --libdir $(ICLibDir)


# Rules

# Run the IC compiler on all *.ic files; since no binary is produced,
# save the compiler output to *.out files.
%.out : %.ic
	@echo ...Compiling $<...
	echo $@ > $@
	echo "Interactive C compiler output for" $< >> $@
	@$(ICCommand) compile $< | tee --append $@



# compilation targets

compileroutput : badouts $(OutputFiles)

# remove the *.out files that report errors so that we can try to make
# them again
badouts :
	find . |grep .out |while read file; do awk '/Error/ {rm FILENAME}' "$$file"; done


sim :
	$(ICCommand) simulate $(SimFile)


diff : 
	@echo Writing $(DiffFile)...
	svn diff | tee $(DiffFile)


clean :
	rm -rf $(shell ls $(ProjectDir) | egrep "*(~|\.(out|diff))")


commit :
	svn ci -m "makefile committing all versioned files"
